package com.example.demo.hystrix;

import com.example.demo.djangoAPI.DjangoAPI;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @ClassName: HystrixServiceFallback
 * @Description:
 * @date 2021/3/29
 * @Copyright
 */

@Component
public class HystrixServiceFallback implements FallbackFactory<DjangoAPI> {

    private static final Logger logger = LoggerFactory.getLogger(HystrixServiceFallback.class);

    @Override
    public DjangoAPI create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();

        if(!StringUtils.isEmpty(msg)){
            logger.error("AccountServiceFallback 中有方法降级，throwable.getMessage():" + msg);
        }
        return new DjangoAPI() {

            @Override
            public String getDjangoTest(String id) {
                return " failed 服务降级";
            }
        };
    }
}
